//-----------------------------------------------------------------------------
// Name: InputManager.h
// Auth: Bradford J. Smith
// Desc: maintains all information needed from frame to frame to manage the
//	input state.
//-----------------------------------------------------------------------------

#ifndef _INPUTMANAGER_
#define _INPUTMANAGER_

#include "SharedConstants.h"
#include "DisplayManager.h"
#include <GL/glut.h>

#include <map>

//-----------------------------------------------------------------------------
// Constants:
//-----------------------------------------------------------------------------

enum eInputConstant
{
	kKeyLetterQ,
	kKeyEscape,

	kMouseButtonLeft,
	kMouseButtonRight,
	kMouseButtonMiddle,

	kKeyUpArrow,
	kKeyDownArrow,
	kKeyRightArrow,
	kKeyLeftArrow,
};

enum eInputState
{
	kInputStateUp,
	kInputStateDown,
	kInputStateError,
};

//-----------------------------------------------------------------------------
// cInputManager:
//-----------------------------------------------------------------------------
class cInputManager
{
public:
	// Constructors
	cInputManager();
	~cInputManager();

	//-----------------------------------------------------------------------------
	eInputState GetInputState(eInputConstant inputConstant);
	// Desc: returns the key state for the given key. If the key is not registered,
	//	it will add the key with a default state of "up"

	void GetMousePosition(int& mouseX, int& mouseY);

	//-----------------------------------------------------------------------------
	bool GetPickCoordinates(tVector3f& origin, tVector3f& end);
	// Desc: unprojects the latest mouse position and returns the point in the near
	//	clip plane and the point in the far clip plane. Returns false if outside 
	//	the boundaries of the window and true otherwise.

	//-----------------------------------------------------------------------------
	void HandleMouseMove(GLint x, GLint y);
	void HandleMouseButton(GLint button, GLint state, GLint x, GLint y);
	void HandleKeyDown(GLubyte key, GLint x, GLint y);
	void HandleKeyUp(GLubyte key, GLint x, GLint y);
	void HandleKeyDownSpecial(GLint key, GLint x, GLint y);
	void HandleKeyUpSpecial(GLint key, GLint x, GLint y);
	// Desc: these methods interpret the OpenGL input and translate it into the 
	//	generic constants.

	//-----------------------------------------------------------------------------
	void SetDebugPickLine();
	void DrawDebugPickLine();
	// Desc: debug functions so we can see where the application thinks our line is
	//	in world space.

private:
	int mLastMouseX;
	int mLastMouseY;

	std::map< eInputConstant, eInputState > mInputStateMap;

	bool mShowDebugPick;
	tVector3f mDebugPickOrigin;
	tVector3f mDebugPickEnd;

};

#endif